<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>协和医院内科专家团队</title>
  <!-- 引入 jQuery -->
  <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
  <style>
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }

    body {
      font-family: "Microsoft YaHei", sans-serif;
      background-color: #f5f7fa;
      color: #333;
    }

    .container {
      max-width: 1200px;
      margin: 0 auto;
      padding: 40px 20px;
    }

    .page-title {
      text-align: center;
      font-size: 32px;
      color: #2a5ca7;
      margin-bottom: 40px;
      padding-bottom: 20px;
      border-bottom: 2px solid #eee;
    }

    .doctor-list {
      display: flex;
      flex-wrap: wrap;
      gap: 30px;
    }

    .doctor-card {
      flex: 1 1 350px;
      background: white;
      border-radius: 10px;
      padding: 25px;
      box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
      transition: transform 0.3s ease;
    }

    .doctor-card:hover {
      transform: translateY(-5px);
    }

    .doctor-name {
      color: #2a5ca7;
      font-size: 24px;
      margin-bottom: 15px;
      padding-bottom: 10px;
      border-bottom: 1px solid #eee;
    }

    .doctor-info p {
      margin: 8px 0;
      line-height: 1.6;
    }

    .doctor-info strong {
      color: #333;
      font-weight: 600;
    }

    /* 新增样式 */
    .doctor-content {
      display: flex;
      gap: 20px;
      align-items: flex-start;
    }

    .doctor-img {
      width: 120px;
      height: 160px;
      object-fit: cover;
      border-radius: 4px;
      flex-shrink: 0;
    }

    .doctor-info {
      flex: 1;
    }

    @media (max-width: 768px) {
      .container {
        padding: 20px 15px;
      }

      .page-title {
        font-size: 28px;
      }

      .doctor-card {
        flex-basis: 100%;
      }
    }
  </style>
</head>

<body>
<div class="container">
  <h1 class="page-title" id="pageTitle">专家团队</h1>

  <div class="doctor-list" id="doctorListContainer">
    <!-- 医生卡片将通过 AJAX 动态加载到这里 -->
  </div>
</div>

<script>
  $(document).ready(function() {

    // 从 cookie 中获取指定名称的值
    function getCookie(name) {
      const value = `; ${document.cookie}`;
      const parts = value.split(`; ${name}=`);
      console.log(parts);
      if (parts.length === 2) return parts.pop().split(';').shift();
    }

    // 获取 URL 中的 departmentId 参数
    function getDepartmentIdFromUrl() {
      const urlParams = new URLSearchParams(window.location.search);
      return urlParams.get('departmentId');
    }

    // 发送 AJAX 请求获取医生信息
    function loadDoctors(departmentId) {
      $.ajax({
        url: `http://localhost:8000/admin/doctorInfo/${departmentId}`,
        headers: {
          'Authorization': `${getCookie('token')}`
        },
        method: 'GET',
        success: function(response) {
          if (response.code === 200 && response.data) {
            const doctors = response.data;
            let doctorHtml = '';

            doctors.forEach(doctor => {
              // 更新页面标题
              if (doctor.deptName) {
                console.log(doctor.deptName);
                $('#pageTitle').text(doctor.deptName + '专家团队');
              }
              doctorHtml += `
                <div class="doctor-card">
                  <div class="doctor-content">
                    <img src="${doctor.picture}" alt="${doctor.name}" class="doctor-img">
                    <div class="doctor-info">
                      <h2 class="doctor-name">${doctor.name}</h2>
                      <p><strong>职务：</strong>${doctor.job}</p>
                      <p><strong>职称：</strong>${doctor.title}</p>
                    </div>
                  </div>
                </div>
              `;
            });
            $('#doctorListContainer').html(doctorHtml);


          } else {
            console.error('Failed to load doctors:', response.message);
          }
        },
        error: function(error) {
          document.cookie = 'token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';
          window.location.href = 'http://localhost:5173';
          console.error('AJAX request failed:', error);
        }
      });
    }

    // 页面加载完成后，根据 URL 参数加载医生信息
    const departmentId = getDepartmentIdFromUrl();
    if (departmentId) {
      loadDoctors(departmentId);
    } else {
      console.error('No departmentId found in URL.');
    }
  });
</script>
</body>


</html>
